home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / wheels1.arc / GETFILE.LIB < prev    next >
Text File  |  1985-06-28  |  4KB  |  116 lines

  1. {@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
  2. The purchaser of these procedures and functions may include them in COMPILED
  3. programs freely, but may not sell or give away the source text.
  4.  
  5.  
  6. GETFILE consists of a set of three procedures based on a variable-type
  7. BUFFER-TYPE, which is the exact "shape" of the information returned by
  8. DOS function calls $4E (Find First matching file) and $4F (Find Next).
  9.  
  10. SetDTA is called by Find_First to Set the Data Transfer Area to the Buffer.
  11.  
  12. Find_First takes as input the file attribute and name-template of the file
  13.   required and returns the actual attribute found, the first matching name,
  14.   and an error code.
  15.  
  16. Find_Next takes no input, but the buffer must be initialized by Find_First.
  17.   The output of Find_Next is the same as that of Find_First.
  18.  
  19. Any program that calls GETFILE must also INCLUDE the standard type definitions
  20. in FILENAME.TYP and REGPACK.TYP.
  21.  
  22. The procedures of GETFILE are used by ALLFILES.LIB for a very handy file
  23. selection module.}
  24. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  25.  
  26.   type
  27.     buffer_type   = record
  28.                       reserved : array[1..21] of byte;
  29.                       attribute: byte;
  30.                       time, date, FileSizeLo, FileSizeHi : integer;
  31.                       name : string[13];
  32.                     end;
  33.   var
  34.     error     : byte;
  35.     filename  : filename_type; {NOTE that filename_type is declared in
  36.                                 the file FILENAME.TYP.  This is in order
  37.                                 to avoid multiple declarations}
  38.     buffer    : buffer_type;
  39.     attribute : byte;
  40. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  41. procedure SetDTA(var buff);
  42. var
  43.   registers : regpack;
  44. begin
  45.   with registers do
  46.     begin
  47.       AX := $1A shl 8;
  48.       DS := seg(buff);
  49.       DX := ofs(buff);
  50.       MSDOS(registers);
  51.     end;
  52. end;
  53. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  54. procedure Find_Next(var att:byte; var filename : filename_type;
  55.                                       var Next_error : byte);
  56. var
  57.   registers  : regpack;
  58.   carry_flag : integer;
  59.   N          : byte;
  60. begin
  61.   buffer.name := '             ';
  62.   with registers do
  63.     begin
  64.       AX := $4F shl 8;
  65.       MSDOS(registers);
  66.       att := buffer.attribute;
  67.       carry_flag := 1 and Flags;
  68.       filename := '             ';
  69.       If carry_flag = 1 then
  70.         Next_error := AX and $00FF
  71.       else
  72.         begin
  73.           Next_error := 0;
  74.           for N := 0 to 12 do FileName[N+1] := buffer.name[N];
  75.         end;
  76.     end;  {with}
  77.   att := buffer.attribute;
  78. end;
  79. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  80. Procedure Find_First (VAR att: byte;
  81.                       var filename: filename_type;
  82.                       var error_code : byte);
  83.  
  84.   var
  85.       registers        :regpack;
  86.       carry_flag       :integer;
  87.       mask, N          :byte;
  88.  
  89.   begin
  90.     SetDTA(buffer);
  91.     filename[Length(filename) + 1] := chr(0);
  92.     buffer.name := '             ';
  93.     With registers do
  94.       begin
  95.         AX := $4E shl 8;
  96.         CX := att;
  97.         DS := Seg(filename);
  98.         DX := Ofs(filename) + 1;
  99.         MsDos(registers);
  100.         att := buffer.attribute;
  101.         { If there was an error set the error code and don't do
  102.           anything else. }
  103.  
  104.         carry_flag := 1 and Flags;
  105.         If carry_flag = 1 then
  106.           begin
  107.             error_code := AX and $00FF;
  108.           end
  109.         else
  110.           begin
  111.             error_code := 0;
  112.             filename := '             ';
  113.             for N := 0 to 12 do FileName[N+1] := buffer.name[N];
  114.           end;
  115.       end;  {with}
  116. end;